#include "Enemy.h"

Enemy::Enemy(void) : mActive(false)
{
}

Enemy::~Enemy(void)
{
}

void Enemy::Load()
{
	msprite.Load("pikachu.png");
}

void Enemy::Unload()
{
	msprite.Unload();
}
void Enemy::Update(float deltaTime)
{
	if(mActive)
	{
		mposition += mvelocity * deltaTime;
		const int kWinWidth = IniFile_GetInt("WinWidth", 800);  // ini files
		const int kWinHeight = IniFile_GetInt("WinHeight", 600);
		const int kThreshhold = msprite.GetWidth();

			mDelay -= deltaTime;
	if(mDelay <= 0.0f)
	{
		
		mDelay = RandomFloat (0.5f, 2.0f);
		mvelocity = SVector2(RandomFloat(-200.0f,200.0f), 200.0f);
		
		
	}
		
		if(mposition.x < -kThreshhold || mposition.x > kWinWidth + kThreshhold ||
			mposition.y < -kThreshhold || mposition.y > kWinHeight + kThreshhold)
		{
			Kill();
		}
	}
}
void Enemy::Render()
{
	if(mActive)
	{
		int width = msprite.GetWidth();
		int height = msprite.GetHeight();
		SVector2 offset(width * 0.5f, height *0.5f);
		SVector2 renderPosition = mposition - offset;
		msprite.SetPosition(renderPosition);
		msprite.Render();
	}
}
void Enemy::Spawn(const SVector2& pos)
{
	mposition = pos;
	mvelocity = SVector2(RandomFloat(-200.0f,200.0f), 200.0f);
	mActive = true;
}
void Enemy::Kill()
{
	mActive = false;
}